package org.wu.framework.lazy.orm.database.sql.expand.database.persistence.cure;

import org.wu.framework.lazy.orm.core.config.prop.LazyDataSourceAttribute;
import org.wu.framework.lazy.orm.database.lambda.LazyBaseDDLOperation;
import org.wu.framework.lazy.orm.database.lambda.LazyBaseDQLOperation;
import org.wu.framework.lazy.orm.database.sql.expand.database.persistence.cure.lazy.LazySchemaCure;
import org.wu.framework.lazy.orm.database.sql.expand.database.persistence.cure.lazy.LazyTableColumnCure;
import org.wu.framework.lazy.orm.database.sql.expand.database.persistence.cure.lazy.LazyTableCure;
import org.wu.framework.lazy.orm.database.sql.expand.database.persistence.factory.LazyOperationDDLProxyFactory;
import org.wu.framework.lazy.orm.database.sql.expand.database.persistence.factory.LazyOperationDQLProxyFactory;

import javax.sql.DataSource;
import java.util.Arrays;
import java.util.List;
import java.util.Map;

/**
 * describe : 治愈适配器工厂
 *
 * @author : Jia wei Wu
 * @version 1.0
 * @date : 2023/1/12 22:29
 */
public class CureAdapterFactory {

    public static CureAdapter createCureAdapter(LazyDataSourceAttribute properties) {
        return new CureAdapter(defaultCureList(properties));
    }

    public static CureAdapter createCureAdapter(Map<String, DataSource> dataSourceMap) {
        return new CureAdapter(defaultCureList(dataSourceMap));
    }

    private static List<Cure> defaultCureList(LazyDataSourceAttribute sourceProperties) {
        LazyBaseDQLOperation lazyBaseDQLOperation = LazyOperationDQLProxyFactory.createLazyDQLOperation(sourceProperties);
        LazyBaseDDLOperation lazyBaseDDLOperation = LazyOperationDDLProxyFactory.createLazyDDLOperation(sourceProperties);
        return Arrays.asList(new LazyTableCure(lazyBaseDDLOperation, lazyBaseDQLOperation),
                new LazyTableColumnCure(lazyBaseDDLOperation, lazyBaseDQLOperation),
                new LazySchemaCure(lazyBaseDDLOperation)
        );
    }

    private static List<Cure> defaultCureList(Map<String, DataSource> dataSourceMap) {
        LazyBaseDQLOperation lazyBaseDQLOperation = LazyOperationDQLProxyFactory.createLazyDQLOperation(dataSourceMap);
        LazyBaseDDLOperation lazyBaseDDLOperation = LazyOperationDDLProxyFactory.createLazyDDLOperation(dataSourceMap);
        return Arrays.asList(new LazyTableCure(lazyBaseDDLOperation, lazyBaseDQLOperation),
                new LazyTableColumnCure(lazyBaseDDLOperation, lazyBaseDQLOperation),
                new LazySchemaCure(lazyBaseDDLOperation)
        );
    }
}
